package cn.rkylin.oms.order.dao;

import cn.rkylin.core.IDataBaseFactory;
import cn.rkylin.oms.order.vo.OrderExportVO;
import cn.rkylin.oms.order.vo.OrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository(value = "orderDAO")
public class OrderDAOImpl implements IOrderDAO {

    @Autowired
    protected IDataBaseFactory dao;

    /**
     * 构造函数
     */
    public OrderDAOImpl() {

    }

    @Override
    public int insert(OrderVO orderVO) throws Exception {
        // TODO Auto-generated method stub
        return dao.insert("insertSelectiveOrder", orderVO);
    }

    @Override
    public int update(OrderVO orderVO) throws Exception {
        // TODO Auto-generated method stub
        return dao.update("updateByPrimaryKeySelectiveOrder", orderVO);
    }
    
    @Override
    public int updateOrderForConsign(OrderVO orderVO) throws Exception {
        return dao.update("updateOrderForConsign", orderVO);
    }

    @Override
    public OrderVO findById(String id) throws Exception {
        List<OrderVO> resultList = dao.findList("selectByPrimaryKeyOrder", id);
        if (resultList != null && resultList.size() > 0) {
            return resultList.get(0);
        }
        return null;
    }

    @Override
    public List<OrderVO> findOtherOrder(OrderVO vo) throws Exception {
        return dao.findAllList("selectOtherOrder", vo);
    }

    /**
     * 获取系统订单售后信息 wangxing add
     *
     * @param orderId
     * @return
     * @throws Exception
     */
    @Override
    public List<OrderVO> getOrderAftersaleInfo(String orderId) throws Exception {
        return dao.find("selectOrderAftersaleByOrderId", orderId);
    }

    @Override
    public List<OrderVO> findByTradeCode(OrderVO vo) throws Exception {
        return dao.findAllList("selectTradeCode", vo);
    }

    @Override
    public int selectCount(Map<String, Object> params) throws Exception {
        List resultList = dao.findList("selectOrderCountToday", params);
        if (resultList != null && resultList.size() > 0) {
            return (Integer)resultList.get(0);
        }
        
        return 0;
    }

    @Override
    public List<OrderExportVO> exportSku(Map map) throws Exception {
        return dao.findForList("exportSku", map);
    }

    @Override
    public int getOngoingOrdersCountBySkuCode(Map paramMap) throws Exception {
        return dao.findOne("getOngoingOrdersCountBySkuCode", paramMap);
    }

}
